# -*- coding: utf-8 -*-
from django.utils.translation import ugettext as _
from django.conf import settings
from django.http import HttpResponse, Http404, QueryDict 
from django.shortcuts import render_to_response, redirect
from django.views.generic.simple import direct_to_template
from catalog.models import *
from django.core.paginator import Paginator
from django.core.context_processors import csrf
from django.template import RequestContext
from django.core.paginator import Paginator
import simplejson
from django.db.models import Q

def index(request, template='catalog/index.html', os_id=None, id=None):
    context = RequestContext(request)
    context.update(csrf(request))
    
    os = os_id
    if os is not None:
        os = OperatinSystem.objects.get(pk=os_id)
    category = None
    if id is not None:
        category = Category.objects.get(pk=id)
    
    context.update({
                    'cl': OperatinSystem.objects.all(),
                    'cur_cat': category,
                    'cur_os': os,
                    })
    return render_to_response(template, context)

def item(request, template='catalog/item.html', id=None):
    context = RequestContext(request)
    context.update(csrf(request))
    
    context.update({
                    'cl': Category.tree.filter(level__lte=0)
                    })
    return render_to_response(template, context)    